<template>
  <page-header-wrapper :title="false">
    <a-card
      title="顾问添加客户审核管理"
    >
<!--      <div class="table-page-search-wrapper">-->
<!--        <a-form-model :model="queryParam" layout="inline">-->
<!--          <a-row :gutter="10">-->
<!--            <a-col :md="6" :sm="24">-->
<!--              <a-form-model-item label="顾问姓名">-->
<!--                              <a-select-->
<!--                                show-search-->
<!--                                v-model="queryParam['uid']"-->
<!--                                placeholder="选择顾问姓名"-->
<!--                                :filter-option="filterOption"-->
<!--                              >-->
<!--                                <a-select-option v-for="(item,index) in adviserOpts" :key="index" :value="index">{{item}}</a-select-option>-->
<!--                              </a-select>-->
<!--              </a-form-model-item>-->
<!--            </a-col>-->
<!--            <a-col :md="6" :sm="24">-->
<!--              <span class="table-page-search-submitButtons">-->
<!--                <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>-->
<!--              </span>-->
<!--            </a-col>-->
<!--          </a-row>-->
<!--        </a-form-model>-->
<!--      </div>-->
      <s-table
        bordered
        ref="table"
        :row-key="(record) => record.customer_id"
        :columns="checkColumns"
        :data="checkData"
      >
        <div
          slot="filterDropdown"
          slot-scope="{ setSelectedKeys, selectedKeys, confirm, clearFilters, column }"
          style="padding: 8px"
        >
          <a-input
            v-ant-ref="c => (searchInput = c)"
            :placeholder="`搜索${column.title}`"
            :value="selectedKeys[0]"
            style="width: 188px; margin-bottom: 8px; display: block;"
            @change="e => setSelectedKeys(e.target.value ? [e.target.value] : [])"
            @pressEnter="() => handleSearch(selectedKeys, confirm, column.dataIndex)"
          />
          <a-button
            type="primary"
            icon="search"
            size="small"
            style="width: 90px; margin-right: 8px"
            @click="() => handleSearch(selectedKeys, confirm, column.dataIndex)"
          >
            搜索
          </a-button>
          <a-button size="small" style="width: 90px" @click="() => handleReset(clearFilters)">
            重置
          </a-button>
        </div>
        <template slot="tm_name" slot-scope="text, record">
          <div v-if="text == ''">{{record.pt_name}}</div>
          <div v-else>{{text}}</div>
        </template>
        <template slot="action" slot-scope="text, record">
          <a-button size="small" type="primary" @click="checkCustomer(record.customer_id)">审核</a-button>
        </template>
      </s-table>
    </a-card>
    <a-modal
      v-model="visible"
      :width="200"
      @ok="onSubmitStatus"
    >
      <a-radio-group v-model="checked">
        <a-radio v-for="(item,index) in checkOpts" :key="index" :value="index">
          {{item}}
        </a-radio>
      </a-radio-group>
    </a-modal>
  </page-header-wrapper>
</template>

<script>
import { STable } from '@/components'
import { getCheck, getCheckList, postCheck } from '@/api/customer'
import col from '@/columns/customer'
const checkColumns = col.check
export default {
  components: {
    STable
  },
  name: 'CustomerCheck',
  data () {
    return {
      checkColumns,
      checkData: parameters => {
        return getCheckList(Object.assign(parameters, this.queryParam)).then(res => {
          this.adviserOpts = res.result.adviser_array
          return res.result
        })
      },
      adviserOpts: {},
      customerId: '',
      checkOpts: {},
      checked: '',
      visible: false,
      queryParam: {}
    }
  },
  methods: {
    checkCustomer (id) {
      this.customerId = id
      getCheck(id).then(res => {
        if (res.status === 0) {
          this.checkOpts = res.result.items
          this.checked = res.result.selection
          this.visible = true
        } else {
          this.$warning({
            title: res.msg
          })
        }
      })
    },
    onCancel () {
      this.visible = false
      this.$refs.table.refresh(true)
    },
    handleSearch (selectedKeys, confirm, dataIndex) {
      confirm()
      this.searchText = selectedKeys[0]
      this.searchedColumn = dataIndex
    },
    handleReset (clearFilters) {
      clearFilters()
    },
    filterOption (input, option) {
      return (option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0)
    },
    onSubmitStatus () {
      postCheck(this.customerId).then(res => {
        if (res.status === 0) {
          this.visible = false
          this.$refs.table.refresh(true)
        } else {
          this.$warning({
            title: res.msg
          })
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
